import type { FormSchemaGetter, VbenFormSchema } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { getPopupContainer } from '@vben/utils';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'departmentName',
    label: '科室名称',
  },
];

export const columns: VxeGridProps['columns'] = [
  {
    title: '科室名称',
    field: 'departmentName',
  },
  {
    field: 'departmentImg',
    title: '科室图片',
    slots: { default: 'departmentImg' },
    minWidth: 80,
  },
  {
    field: 'departmentMaxImg',
    title: '科室大图',
    slots: { default: 'departmentMaxImg' },
    minWidth: 80,
  },
  {
    title: '医院',
    field: 'hospitalId',
  },
  {
    title: '科室备注',
    field: 'departmentRemark',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    resizable: false,
    width: 'auto',
  },
];

export const modalSchema = (
  handleUpload: (file: File) => void,
  handleRemove: () => void,
  handleMaxUpload: (file: File) => void,
  handleMaxRemove: () => void,
): VbenFormSchema[] => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'id',
    label: '科室ID',
  },
  {
    component: 'Select',
    componentProps: {
      getPopupContainer,
      optionFilterProp: 'label',
      optionLabelProp: 'label',
      placeholder: '请先选择医院',
      allowClear: true,
    },
    fieldName: 'hospitalId',
    help: '不选择医院，表示为公共科室',
    label: '医院',
  },
  {
    component: 'Upload',
    componentProps: {
      // 更多属性见：https://ant.design/components/upload-cn
      accept: '.png,.jpg,.jpeg',
      // 自动携带认证信息
      // customRequest: uploadApi,
      disabled: false,
      maxCount: 1,
      multiple: false,
      showUploadList: true,
      // 上传列表的内建样式，支持四种基本样式 text, picture, picture-card 和 picture-circle
      listType: 'picture-card',
      beforeUpload: (file: File) => {
        handleUpload(file);
        return false;
      },
      onRemove: (_file: File) => {
        handleRemove();
      },
    },
    fieldName: 'departmentImg',
    label: '科室图片',
    renderComponentContent: () => {
      return {
        default: () => '上传图片',
      };
    },
    rules: 'required',
  },
  {
    component: 'Upload',
    componentProps: {
      // 更多属性见：https://ant.design/components/upload-cn
      accept: '.png,.jpg,.jpeg',
      // 自动携带认证信息
      // customRequest: uploadApi,
      disabled: false,
      maxCount: 1,
      multiple: false,
      showUploadList: true,
      // 上传列表的内建样式，支持四种基本样式 text, picture, picture-card 和 picture-circle
      listType: 'picture-card',
      beforeUpload: (file: File) => {
        handleMaxUpload(file);
        return false;
      },
      onRemove: (_file: File) => {
        handleMaxRemove();
      },
    },
    fieldName: 'departmentMaxImg',
    label: '科室大图',
    renderComponentContent: () => {
      return {
        default: () => '上传大图',
      };
    },
    dependencies: {
      required(values) {
        const { hospitalId } = values;
        return !hospitalId;
      },
      triggerFields: ['hospitalId'],
    },
  },
  {
    component: 'Input',
    fieldName: 'departmentName',
    label: '科室名称',
    rules: 'required',
  },
  {
    component: 'Textarea',
    fieldName: 'departmentRemark',
    label: '科室备注',
    componentProps: {
      rows: 4,
      placeholder: '请输入科室备注',
    },
  },
];
